import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

# 创建数据
x = np.random.rand(50)
y = np.random.rand(50)
z = np.random.rand(50)
colors = np.random.rand(50)  # 用于颜色映射
sizes = 1000 * np.random.rand(50)  # 点的大小

# 创建3D图形对象
fig = plt.figure(figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d')

# 绘制三维散点图
scatter = ax.scatter(x, y, z, c=colors, s=sizes, alpha=0.6, cmap='viridis')

# 添加颜色条和标签
fig.colorbar(scatter, ax=ax, label='Value')
ax.set_xlabel('X轴')
ax.set_ylabel('Y轴')
ax.set_zlabel('Z轴')
ax.set_title('三维散点图示例')

plt.show()